package com.dlut.txy.designpattern.listener.impl;


import com.dlut.txy.designpattern.listener.CommonManager;
import com.dlut.txy.designpattern.listener.EventListener;
import com.dlut.txy.designpattern.listener.PublishResult;
import com.dlut.txy.designpattern.listener.event.QrcodeStatusModifyEvent;

public class QrcodeStatusModifyManager extends CommonManager<QrcodeStatusModifyEvent> {
    @Override
    public PublishResult publish(QrcodeStatusModifyEvent event) {
        if(this.listenerMap==null || this.listenerMap.size()==0) {
            return PublishResult.buildSuccess();
        }
        for (EventListener<QrcodeStatusModifyEvent> eventListener : listenerMap.values()) {
            if(eventListener instanceof QrcodeStatusModifyListener) {
                QrcodeStatusModifyListener qrcodeStatusModifyListener = (QrcodeStatusModifyListener) eventListener;
                if(event instanceof QrcodeStatusModifyEvent.Created) {
                    qrcodeStatusModifyListener.consumeCreated((QrcodeStatusModifyEvent.Created) event);
                } else if(event instanceof QrcodeStatusModifyEvent.Scanned) {
                    qrcodeStatusModifyListener.consumeScanned((QrcodeStatusModifyEvent.Scanned)event);
                } else if(event instanceof QrcodeStatusModifyEvent.Expired) {
                    qrcodeStatusModifyListener.consumeExpired((QrcodeStatusModifyEvent.Expired) event);
                }
//                throw new Exception("不支持的事件类型");
            }
//            throw new Exception("不支持的监听器类型");
        }
        return PublishResult.buildSuccess();
    }
}
